// logs.js
const util = require('../../utils/util.js')
Page({
  data: {
    num: 0,
    lists: ["服务客户", "选择服务客户", "散客"],
    sum: true,
    payment: [{
        money: 3632,
        moneySum: '00',
        discount: 120,
        discountSum: '00',
        payee: "张淑芬(高级技师)",
        sum: '3'
      },
      {
        money: 522,
        moneySum: '00',
        discount: 200,
        discountSum: '00',
        payee: "李淑芬(高级技师)",
        sum: '1'
      },
      {
        money: 36322,
        moneySum: '00',
        discount: 200,
        discountSum: '00',
        payee: "黄淑芬(高级技师)",
        sum: '2',
      },
    ],
    counter: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '', '0', '.'],
    Calculate: null,
    Discounts: 0,
  },
  GetNum: function (e) {
    let index = e.currentTarget.dataset.id
    this.setData({
      num: index
    })
    this.setData({
      sum: !this.data.sum
    })
    // if(index == 0){
    //   this.setData({
    //     sum: false
    //   })
    //   return;
    // }
    // this.setData({
    //   sum: true
    // })
  },
  Getshow: function () {
    let obj = this.data.sum
    this.setData({
      sum: !obj
    })
  },
  GetDel: function (e) {
    let index = e.currentTarget.dataset.id
    this.data.payment.splice(index, 1)
    this.setData({
      payment: this.data.payment
    })
    // console.log(this.data.payment)
    this.data.Calculate = 0;
    if (this.data.payment.length == 0) {
      this.setData({
        Calculate: 0
      })
      console.log("sss")
      return;
    }
    this.GetSum();
  },
  GetDiscounts(e) {
    let index = e.currentTarget.dataset.index
    if (this.data.payment[index].sum == 0) {
      return;
    }
    let DiscountsSum = e.currentTarget.dataset.id;
    this.setData({
      Discounts: DiscountsSum + this.data.Discounts
    })
    this.setData({
      Calculate: this.data.Calculate - this.data.Discounts
    })
    let jian = this.data.payment[index].sum - 1
    let datalists = []
    this.data.payment.forEach((item, i) => {
      if (index == i) {
        item.sum = jian
      }
      let lists = item;
      datalists.push(lists)
    })
    this.setData({
      payment: datalists
    })
  },
  GetSum: function () {
    this.data.payment.forEach(item => {
      let MathSum = item.money;
      this.setData({
        Calculate: MathSum + this.data.Calculate
      })
    });
  },

  onLoad() {
    // this.setData({
    //   logs: (wx.getStorageSync('logs') || []).map(log => {
    //     return {
    //       date: util.formatTime(new Date(log)),
    //       timeStamp: log
    //     }
    //   })
    // })
    this.GetSum()
  }
})